<template>
  <h1>循环指令</h1>
  <ul>
<!--    item 从1开始,每执行一次,item的值就+1, 一直到数字n -->
<!--    v-for 的效果:执行5次,生成5个li 里面的数字根据循环次数递增-->
    <li v-for="(item,index) in 5" :key="index">{{item}}</li>
  </ul>
  <ul>
    <li v-for="p in productArr">{{ p.title+p.price+p.num }}</li>
  </ul>
  <table border="1px" align="center">
    <tr>
      <th>商品序号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品数量</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,index) in productArr" :key="index">
      <td>{{index+1}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.num}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";
const productArr =ref(
    [
      {title:'苹果',price:50,num:10},
      {title:'香蕉',price:30,num:20},
      {title:'橘子',price:20,num:30},
      {title:'梨',price:10,num:40},
      {title:'桃子',price:40,num:50}
    ]
)
const del = (index)=>{
  if (confirm('确定删除吗')){
    productArr.value.splice(index,1);
  }

}
</script>


<style scoped>

</style>